package fanxing;

public class JiHe<T> {
    private T[] arr;//定义一个集合
    private int size;//定义一个变量来保存集合的长度
    public JiHe(int size) {
        this.size = size;
        arr = (T[]) new Object[size];//强制转换为T[]类型的数组
    }
    public void set(int index, T val) {
        arr[index] = val;
    }
    public T get(int index) {
        return arr[index];
    }
    public void show() {
        for (T e : arr) {//数组集合元素循环 T是数组类型，e是数组元素，arr是数组
            //System.out.print(e + "\t");//println表示换行显示\
            System.out.println(e);
        }
        System.out.println();
    }

    public static void main(String[] args) {
        //JiHe<String> jh = new JiHe<>(5);
        /*jh.set(2, "小白龙");
        jh.set(0, "猪八戒");*/
        JiHe<Integer> jh = new JiHe<>(5);
        jh.set(2, 45);
        jh.set(0, 60);
        jh.show();
        System.out.println("-----------------------------");
        System.out.println(jh.get(2));//显示集合中的某个元素
        System.out.println("-----------------------------");
        JiHe<Student> jh2=new JiHe(5);
        Student s1=new Student("孙悟空",500);
        Student s2=new Student("牛魔王",400);
        Student s3=new Student("红孩儿",100);
        jh2.set(1,s1);
        jh2.set(3,s2);
        jh2.set(4,s3);
        jh2.show();
    }
    public static void out(JiHe<? extends Number>jh){

    }
}
